/**
 * Created by ChenChen on 2016/7/21.
 */
require.config({
    baseUrl: '../../assets/global/scripts/',
    paths:{
        avalon: 'avalon',
        domReady:'domReady',
        mmHistory: 'mmHistory',
        mmRouter: 'mmRouter',
        jquery: 'jq'
    },
    shim:{
        avalon: { exports: "avalon" },
        mmHistory:{ deps: ['avalon']},
        mmRouter:{ deps: ['avalon']}
    }
});

require(['mmHistory','mmRouter',"domReady!"], function() {
    var vm = avalon.define({
        $id: "index",
        pageUrl:"general-search.html",  //默认
        array:[],
        ready:function(){
          vm.togglenavbar(e);
            vm.GeneralSearch();
        },
        //导航栏设置--begin
        leftnavbar:[{
            name:"基本搜索",
            href:"#!/general-search",
            en:"general-search",
            hide:"",
            start:"start",
            active:"active",
            icon:"icon-search",
            select:"selected"
        },{
            name:"高级搜索",
            href:"#!/advanced-search",
            en:"advanced-search",
            hide:"",
            start:"",
            active:"",
            icon:"icon-zoom-in",
            select:""
        },{
            name:"新增成员",
            href:"#!/import",
            en:"import",
            hide:"",
            start:"",
            active:"selected",
            icon:"icon-plus",
            select:""
        },{
            name:"编辑资料",
            href:"#!/edit",
            en:"edit",
            hide:"",
            start:"",
            active:"",
            icon:"icon-pencil",
            select:""
        }],
        //导航栏设置--end
        //用户自己的信息--begin
        userinfo:[{
            Name:"鄢鹏权",
            Sex:"male",
            Rand:"鹏",
            Phone:"15822222222",
            BranchID:"xx",
            Province:"四川",
            City:"绵阳市",
            District:"西南科技大学",
            Street:"XXXXX",
            Birthday:"1990年XX月xx日",
            HighestDegree:"本科",
            NowCompany:"碳素云科技",
            NowJob:"运营总监",
            NowAbility:"网站开发",
            SonCount:"0",
            ParentUID:"111",
            CTime:"12131313",
        }],
        //用户自己的信息--end
        //改变侧边栏的样式--begin
        togglenavbar:function(e){
            for (i=0;i<vm.leftnavbar.length;i++){
                vm.leftnavbar[i].active="";
                vm.leftnavbar[i].start="";
                vm.leftnavbar[i].select="";
            };
            vm.leftnavbar[e].active="active";
            vm.leftnavbar[e].start="start";
            vm.leftnavbar[e].select="selected";
        },
        //改变侧边栏的样式--end
        //基本搜索功能--begin
        SearchName:"",
        refresh:false,
        refreshtime:"",
        GeneralSearch:function(){
            $.ajax({
                url:'http://yan.dev.tansuyun.cn/http.php?i=Yan/Member/search',
                type:'POST',
                data:{
                    W:{

                    },
                    Keyword:vm.SearchName,
                },
                success: function (data) {
                    data = JSON.parse(data)
                    vm.array=data.L;
                    vm.refreshtime=new Date;
                    vm.refresh=true;
                }
            })
        },
        //基本搜索功能--end




    });//avalon-define---end
    //路由设置--begin
    function callback() {
        if(this.path==="/index"){
            vm.pageUrl="general-search.html"; //如果url后缀变成"#!/index"，则pageUrl为“general-search”
        }else {
            var path_tail = this.path.replace(/\//, ""); //去掉this.path值的第一个斜杠
            vm.pageUrl = path_tail + ".html";  //动态修改pageUrl属性值

        }
    }
    //路由设置--end
    avalon.router.get("/*path", callback); //劫持url hash并触发回调
    avalon.history.start(); //历史记录堆栈管理
    avalon.scan();
    //初始化读取数据--begin
    window.setTimeout(function(){
        $.ajax({
            url:'http://yan.dev.tansuyun.cn/http.php?i=Yan/Member/search',
            type:'POST',
            data:{
                W:{

                },
                Keyword:'',
            },
            success: function (data) {
                data = JSON.parse(data)
                vm.array=data.L;
            }
        })
    },100)
    //初始化读取数据--end
});


